Skip to content

Conversation

@Cloxl
Copy link
Owner

@Cloxl Cloxl commented Jan 13, 2026

Fixes #84

Summary by Sourcery

错误修复:

  • 修复错误的 GET 负载编码方式:现在对参数值进行 URL 编码,而不是仅替换字符 '='
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Fix incorrect GET payload encoding by applying URL encoding to parameter values instead of only replacing '=' characters.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 13, 2026

评审者指南(在小型 PR 上折叠)

评审者指南

重构 GET 查询参数的构建逻辑,使用标准的 URL 百分号编码(允许逗号)来处理参数值,替换之前仅对 = 做自定义编码的方案,以便在客户端请求签名中正确处理非 ASCII 字符。

客户端中 GET 参数编码的流程图

flowchart TD
  Start["_build_content_string called"] --> CheckMethod{"method == 'GET'?"}
  CheckMethod -- "No" --> ReturnURI["Return uri unchanged"]
  CheckMethod -- "Yes" --> CheckPayload{"payload is empty?"}
  CheckPayload -- "Yes" --> ReturnURIGet["Return uri unchanged"]
  CheckPayload -- "No" --> InitParams["Initialize empty params list"]

  InitParams --> LoopItems["For each key, value in payload.items()"]

  LoopItems --> CheckListTuple{"value is list or tuple?"}
  CheckListTuple -- "Yes" --> JoinList["value_str = comma-joined string of items"]
  CheckListTuple -- "No" --> CheckNone{"value is not None?"}
  CheckNone -- "Yes" --> ToString["value_str = str(value)"]
  CheckNone -- "No" --> EmptyStr["value_str = empty string"]

  JoinList --> EncodeValue
  ToString --> EncodeValue
  EmptyStr --> EncodeValue

  EncodeValue["encoded_value = urllib.parse.quote(value_str, safe=',' )"] --> AppendParam["Append f'key=encoded_value' to params list"]
  AppendParam --> NextItem{"More items in payload?"}
  NextItem -- "Yes" --> LoopItems
  NextItem -- "No" --> BuildQuery["Return f'{uri}?{ '&'.join(params) }'"]
Loading

文件级变更

Change Details Files
使用支持非 ASCII 字符、且保留逗号的 urllib.parse.quote URL 编码来替换对 GET 查询参数值的自定义手动编码实现。
  • 将 payload 转换为查询字符串的逻辑,从列表推导式改为显式循环,以提升可读性并便于逐步处理。
  • 对列表/元组类型的 payload 值,通过逗号拼接为字符串;对其他非 None 的值转换为字符串;None 则默认转换为空字符串。
  • 对每个值字符串使用 urllib.parse.quote 编码,并将逗号标记为安全字符从而不进行百分号编码,然后将最终查询字符串组装为 uri 加上 ? 和以 & 连接的 key=value 对。
src/xhshow/client.py

与关联 issue 的对照评估

Issue Objective Addressed Explanation
#84 更新 GET 请求参数编码,使非 ASCII 字符进行 URL 编码,而逗号(,)保持未编码状态,以符合 XHS 签名要求。
#84 在客户端提供符合规范的 GET URL 构建方法,使 GET 请求链接根据所需编码规则构建。

使用技巧与命令

与 Sourcery 互动

  • 触发新评审: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的评审评论。
  • 从评审评论生成 GitHub issue: 在某条评审评论下回复,要求 Sourcery 从该评论创建 issue。你也可以在评论中回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai 即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写上 @sourcery-ai summary,即可在指定位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来在任意时间(重新)生成摘要。
  • 生成评审者指南: 在 pull request 上评论 @sourcery-ai guide,即可在任意时间(重新)生成评审者指南。
  • 解决所有 Sourcery 评论: 在 pull request 上评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。当你已经处理完所有评论且不想再看到它们时,这非常有用。
  • 忽略所有 Sourcery 评审: 在 pull request 上评论 @sourcery-ai dismiss,以忽略所有已有的 Sourcery 评审。若你希望从一次全新的评审开始,这尤其有用——别忘了再评论 @sourcery-ai review 来触发新的评审!

自定义你的体验

打开你的 dashboard 可以:

  • 启用或禁用评审功能,例如 Sourcery 生成的 pull request 摘要、评审者指南等。
  • 更改评审语言。
  • 添加、删除或编辑自定义评审说明。
  • 调整其他评审设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors GET query parameter construction to use standard URL percent-encoding for values (while allowing commas), replacing the prior custom '='-only encoding, to correctly handle non-ASCII characters in client request signing.

Flow diagram for GET parameter encoding in client

flowchart TD
  Start["_build_content_string called"] --> CheckMethod{"method == 'GET'?"}
  CheckMethod -- "No" --> ReturnURI["Return uri unchanged"]
  CheckMethod -- "Yes" --> CheckPayload{"payload is empty?"}
  CheckPayload -- "Yes" --> ReturnURIGet["Return uri unchanged"]
  CheckPayload -- "No" --> InitParams["Initialize empty params list"]

  InitParams --> LoopItems["For each key, value in payload.items()"]

  LoopItems --> CheckListTuple{"value is list or tuple?"}
  CheckListTuple -- "Yes" --> JoinList["value_str = comma-joined string of items"]
  CheckListTuple -- "No" --> CheckNone{"value is not None?"}
  CheckNone -- "Yes" --> ToString["value_str = str(value)"]
  CheckNone -- "No" --> EmptyStr["value_str = empty string"]

  JoinList --> EncodeValue
  ToString --> EncodeValue
  EmptyStr --> EncodeValue

  EncodeValue["encoded_value = urllib.parse.quote(value_str, safe=',' )"] --> AppendParam["Append f'key=encoded_value' to params list"]
  AppendParam --> NextItem{"More items in payload?"}
  NextItem -- "Yes" --> LoopItems
  NextItem -- "No" --> BuildQuery["Return f'{uri}?{ '&'.join(params) }'"]
Loading

File-Level Changes

Change Details Files
Replace custom manual encoding of GET query parameter values with urllib.parse.quote-based URL encoding that supports non-ASCII characters while preserving commas.
  • Change payload-to-query-string logic to build params via an explicit loop instead of a list comprehension for clarity and stepwise processing.
  • Normalize list/tuple payload values by joining with commas, and convert other non-None values to strings, defaulting None to an empty string.
  • Apply urllib.parse.quote to each value string with commas marked as safe so they are not percent-encoded, then assemble the final query string as uri plus ? and &-joined key=value pairs.
src/xhshow/client.py

Assessment against linked issues

Issue Objective Addressed Explanation
#84 Update GET request parameter encoding so that non-ASCII characters are URL-encoded while commas (,) remain unencoded, in accordance with XHS signature requirements.
#84 Provide a compliant GET URL construction method in the client so that GET request links are built according to the required encoding rules.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并提供了一些整体性的反馈:

  • 建议像对参数值一样,对参数键也应用相同的 urllib.parse.quote 编码,这样可以让键中出现的非 ASCII 或保留字符与值的处理方式保持一致。
  • 可以考虑将查询字符串的构造逻辑集中到一个小的辅助函数中,这样编码规则(例如 safe=',')只定义在一个地方,如果签名需求以后再次变化,也更便于审查和调整。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- Consider applying the same `urllib.parse.quote` encoding to the parameter keys as you do to the values so that non-ASCII or reserved characters in keys are handled consistently with values.
- It may be worth centralizing the query-string construction into a small helper function so that the encoding rules (e.g., `safe=','`) are defined in one place and easier to audit or adjust if the signature requirements change again.

## Individual Comments

### Comment 1
<location> `src/xhshow/client.py:52` </location>
<code_context>
-                ]
+                params = []
+                for key, value in payload.items():
+                    if isinstance(value, list | tuple):
+                        value_str = ','.join(str(v) for v in value)
+                    elif value is not None:
</code_context>

<issue_to_address>
**issue (bug_risk):** Using `list | tuple` in `isinstance` is invalid at runtime; use a tuple of types instead.

`list | tuple` creates a `types.UnionType`, which `isinstance` does not accept and will raise `TypeError` at runtime. Use `isinstance(value, (list, tuple))` to preserve the intended behavior.
</issue_to_address>

Sourcery 对开源项目是免费的——如果你喜欢我们的评审,请考虑分享它们 ✨
帮我变得更有用!请对每条评论点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • Consider applying the same urllib.parse.quote encoding to the parameter keys as you do to the values so that non-ASCII or reserved characters in keys are handled consistently with values.
  • It may be worth centralizing the query-string construction into a small helper function so that the encoding rules (e.g., safe=',') are defined in one place and easier to audit or adjust if the signature requirements change again.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider applying the same `urllib.parse.quote` encoding to the parameter keys as you do to the values so that non-ASCII or reserved characters in keys are handled consistently with values.
- It may be worth centralizing the query-string construction into a small helper function so that the encoding rules (e.g., `safe=','`) are defined in one place and easier to audit or adjust if the signature requirements change again.

## Individual Comments

### Comment 1
<location> `src/xhshow/client.py:52` </location>
<code_context>
-                ]
+                params = []
+                for key, value in payload.items():
+                    if isinstance(value, list | tuple):
+                        value_str = ','.join(str(v) for v in value)
+                    elif value is not None:
</code_context>

<issue_to_address>
**issue (bug_risk):** Using `list | tuple` in `isinstance` is invalid at runtime; use a tuple of types instead.

`list | tuple` creates a `types.UnionType`, which `isinstance` does not accept and will raise `TypeError` at runtime. Use `isinstance(value, (list, tuple))` to preserve the intended behavior.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

]
params = []
for key, value in payload.items():
if isinstance(value, list | tuple):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk):isinstance 中使用 list | tuple 在运行时是无效的;请改用类型元组。

list | tuple 会创建一个 types.UnionTypeisinstance 不接受该类型,并会在运行时抛出 TypeError。请使用 isinstance(value, (list, tuple)) 来保持原本的预期行为。

Original comment in English

issue (bug_risk): Using list | tuple in isinstance is invalid at runtime; use a tuple of types instead.

list | tuple creates a types.UnionType, which isinstance does not accept and will raise TypeError at runtime. Use isinstance(value, (list, tuple)) to preserve the intended behavior.

@Cloxl Cloxl merged commit 751f157 into master Jan 13, 2026
4 checks passed
@Cloxl Cloxl mentioned this pull request Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get请求体处理

2 participants